<template>
  <el-card style="width: 1400px; margin: 0 auto">
    <template #header>
      <div class="header">
        <div>
          <el-icon class="icon" size="20" @click="goBack"><ArrowLeft /></el-icon>
          <span>查看</span>
        </div>
        <el-button type="primary" @click="shiftToCollaborativeGovernance(detailInfo.sorgRiskId)" v-if="detailInfo.state != 2" > 转入协同治理 </el-button>
      </div>
    </template>
    <div class="card" v-loading="loading">
      <div class="title">风险预警详情</div>
      <div class="content">
        <el-row :gutter="20" style="padding-top: 30px">
          <el-col :span="10">
            <div class="info">
              <div class="info-label">来源</div>
              <div class="info-input">{{ getSource(detailInfo.source) }}</div>
            </div>
          </el-col>
          <el-col :span="14">
            <div class="info">
              <div class="info-label" style="width: 144px">社会组织名称</div>
              <div class="info-input">{{ detailInfo.riskName || '' }}</div>
            </div>
          </el-col>
          <el-col :span="10">
            <div class="info">
              <div class="info-label">风险类别</div>
              <div class="info-input">{{ detailInfo.riskType || '' }}</div>
            </div>
          </el-col>
          <el-col :span="14">
            <div class="info">
              <div class="info-label" style="width: 144px">
                是否转入协同治理
              </div>
              <div class="info-input">{{ detailInfo.state === 2 ? '是' : '否' }}</div>
            </div>
          </el-col>
          <el-col :span="24">
            <div class="info">
              <div class="info-label">佐证材料</div>
              <div class="info-input">
                <PreviewFile :tableData="detailInfo.file"/>
              </div>
            </div>
          </el-col>
          <el-col :span="24">
            <div class="info">
              <div class="info-label">
                <span style="color: #ff0000">*</span>风险详情
              </div>
              <div class="info-input">
                {{ detailInfo.riskDetail || '' }}
              </div>
            </div>
          </el-col>
          <el-col :span="24">
            <div class="info">
              <div class="info-label">整改要求</div>
              <div class="info-input">
                {{ detailInfo.rect || '' }}
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
      <div class="title" v-if="detailInfo.isHandle === 1">风险预警处理</div>
      <div class="content" v-if="detailInfo.isHandle === 1">
        <el-row :gutter="20" style="padding-top: 30px">
          <el-col :span="24">
            <div class="info">
              <div class="info-label">处理情况</div>
              <div class="info-input">
                {{ detailInfo.handleSituationl || '' }}
              </div>
            </div>
          </el-col>
          <el-col :span="24">
            <div class="info">
              <div class="info-label">佐证材料</div>
              <div class="info-input">
                <PreviewFile :tableData="detailInfo.handleFile"/>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { msgDetail, riskChange, riskDetail, soptCheckDetail } from "@/api/spotCheck/spotCheck";
import { useRoute, useRouter } from 'vue-router'
import { ArrowLeft } from '@element-plus/icons-vue'
import { dateFormat } from '@/utils'
import PreviewFile from '@/views/spotCheck/components/previewFile/previewFile.vue'
import { ElMessage, ElMessageBox } from "element-plus";

const router = useRouter()

const route = useRoute()
const detailInfo = ref('')
const loading = ref(false)
onMounted(() => {
  reload()
})

//转入协同治理
const shiftToCollaborativeGovernance = (sorgRiskId) => {
  ElMessageBox.confirm('确定要将该风险转入协同治理吗？', '温馨提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      riskChange({ sorgRiskId }).then((res) => {
        ElMessage.success('转入成功！')
        reload()
      })
    })
    .catch(() => {})
}

const reload = () => {
  loading.value = true
  riskDetail({ sorgRiskId: route.query.id })
    .then((res) => {
      detailInfo.value = res.data
    })
    .finally(() => {
      loading.value = false
    })
}
//返回
const goBack = () => {
  router.go(-1)
}

const getSource = (v) => {
  let name = ''
  try {
    name = [
      '数据比对',
      '年度检查',
      '抽查检查',
      '审计巡视巡查',
      '网络舆情',
      '其他'
    ][v - 1]
  } catch (e) {}
  return name
}
</script>

<style scoped lang="scss">
.info {
  display: flex;
  margin-bottom: 30px;
  .info-label {
    width: 108px;
    font-family: Source Han Sans SC, Source Han Sans SC;
    font-weight: 300;
    font-size: 18px;
    color: #666666;
    margin-right: 20px;
    display: inline-flex;
    justify-content: flex-end;
    align-items: center;
    height: 30px;
  }
  .info-input {
    flex: 1;
    font-family: Source Han Sans SC, Source Han Sans SC;
    font-weight: 400;
    font-size: 18px;
    color: #333333;
    line-height: 30px;
    min-width: 0;
  }
}

.upload {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.uploadListTable {
  border: 1px solid #e9e9e9;
}

:deep(.uploadListTable th) {
  background: #f5f6f8;
  font-weight: 300;
  font-size: 16px;
  color: #333333;
  height: 38px;
}
.title {
  font-weight: 500;
  font-size: 18px;
  color: #333333;
  padding-bottom: 10px;
  border-bottom: 1px solid #e9e9e9;
  padding-left: 20px;
}
:deep(.el-card__body) {
  padding: 20px 0;
}
.card {
  box-sizing: border-box;
}
.content {
  padding: 0 20px;
  box-sizing: border-box;
}
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  .icon {
    margin-right: 16px;
    cursor: pointer;
  }
  span {
    font-family: Source Han Sans SC, Source Han Sans SC;
    font-weight: 500;
    font-size: 20px;
    color: #333333;
  }
}
</style>
